package com.yequan.jms.p2p.destination;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.util.Map;

public class Producer {

    public static void main(String[] args) {
        try {
            int i = 0;
            ActiveMQConnectionFactory mqConnectionFactory =
                    new ActiveMQConnectionFactory("admin", "admin", "tcp://192.168.157.141:61616");
            Connection connection = mqConnectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createQueue("test_destination");
            MessageProducer producer = session.createProducer(destination);
            while (true) {
                i++;
                TestBean testBean = new TestBean();
                testBean.setName("tom--->>>" + i);
                testBean.setAge(23);
                ObjectMessage message = session.createObjectMessage(testBean);
                producer.send(message);
                Thread.sleep(3000);
            }
        } catch (JMSException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }


}
